﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KNXObjects
{
    public class DateObject : GenericObjectBase<DateTime>
    {
        #region ObjectBase Implementations

        public override string DataPointEISName
        {
            get { return "EIS4"; }
        }

        public override string DataPointID
        {
            get { return "11.001"; }
        }

        public override string ToString()
        {
            return Value.ToString("yyyy-MM-dd");
        }

        public override void SetValue(string value)
        {
            if (value.ToLower() == "now")
            {
                Value = DateTime.Now;
            }
            else
            {
                DateTime val;
                if (!DateTime.TryParse(value, out val))
                    throw new ApplicationException("DateObject, cannot parse input string as datetime. Val : " + value);

                Value = val;
            }
        }        

        #endregion

        #region ctor

        public DateObject(string id, string address, string name, string flags)
            : base(id, address, name, flags)
        {
        }
        public DateObject()
        {
            Value = DateTime.Now;
        }

        public DateObject(string value)
        {
            SetValue(value);
        }

        #endregion
    }
}
